#!/bin/bash

tar_dir=/tmp/$(date +%N%s)
if [ $1 ]; then
    if [ -f $1 ]; then
        if [ ! -d $tar_dir ]; then
            mkdir $tar_dir
        fi
        tar -xf $1 -C $tar_dir &>/dev/null
        if [ $? -eq 0 ]; then
            cd $tar_dir
            for i in *;
            do
                scp $i root@$i:/opt/fusionstack/license &>/dev/null
                if [ $? -eq 0 ]; then
                    echo "Node $i registered successful"
                else
                    echo "$i not a valid hostname"
                fi
            done
        else
            echo "$1 not a tar archives"
        fi
        rm -rf $tar_dir
    else
        echo "Please input license tar archives path"
    fi
else
    echo "Please input license tar archives path"
fi
